<?php

/**
 * @author lebachvu
 * @copyright 2012
 */
 
 abstract class Node{
    private $message;
    
    public function __construct(){
        $this->message = array();
        $this->debug(__CLASS__. " constructer called.<br/>");            
    }
    
    public function __destruct(){
        $this->debug(__CLASS__. " destruct called.<br/>");
        $this->dumpDebug();
    }
    
    protected function debug($msg){
        $this->message[] = $msg;
    }
    
    private function dumpDebug(){
        echo implode("\n", $this->message);
    }
    
    public abstract function getView();
}

Class ForumTopic extends Node{
    private $message;
    
    public function __construct(){
        parent::__construct();
        $this->debug(__CLASS__." constructor called.<br/>"); 
    }
    
    public function __destruct(){
        $this->debug(__CLASS__." destructor called.<br/>");
        parent::__destruct();
    }
    
    public function getView(){
        return "This is a View into ". __CLASS__;
    }
}


//$forum = new ForumTopic();

/* Output:
Node constructor called.
ForumTopic constructor called.
ForumTopic destructor called.
Node destructor called.
*/

//$topic = new ForumTopic();
//echo "---------------------<br/>";
//$topic = null;
//echo "---------------------<br/>";

/* Output:
---------------------
Node constructor called.
ForumTopic constructor called.
ForumTopic destructor called.
Node destructor called.
---------------------
*/

$topic = new ForumTopic();
$reference = $topic;
echo "---------------------\n";
$topic = null;
echo "---------------------\n";
/* Output:
---------------------
---------------------
Node constructor called.
ForumTopic constructor called.
ForumTopic destructor called.
Node destructor called.
*/

?>